
	footer.init();
	var data=window.sessionStorage.getItem('setAddr');
	data=JSON.parse(data);
	console.log(JSON.stringify(data));
	var mess = '';
	var type = data.type;
	var title = data.title;
	var addids = data.id;
	header.init(title);
	if(type == 2){
		console.log(JSON.stringify(data.mess));
		mess = data.mess;
		var areas = mess.area;
		areas =areas.split(' ');
		$('.aName').val(mess.uname);
		$('.inputTel input').val(mess.tel);
		$('#cityResult3').text(areas[0]+' '+areas[1]+' '+areas[2]);
		$('.dAddr').val(mess.addr);
		$('.inputCard input').val(mess.idcard);
		$('#cityResult3').attr('data-prov',mess.prov);
		$('#cityResult3').attr('data-city',mess.city);
		$('#cityResult3').attr('data-area',mess.areaid);
		if(mess.is_default=="1"){
			$('#switch').find('mui-switch-handle').attr('style','transition-duration: 0.2s; transform: translate(43px, 0px)');
			$('#switch').addClass('mui-active');
		}
	}
	
window.onload =function(){
	
	$('body').on('click','.inputTel',function(){
		$(this).find('input').focus();
		$('body').on('blur','.inputTel input',function(){//验证手机号
			var tel = $(this).val();
			var myreg =/^1[3|4|5|7|8]\d{9}$/; 
			if(!tel){
				layer.msg('手机号不能为空！');
				return;
			}else if(!myreg.test(tel)){
				layer.msg('请输入有效的手机号！');
				$(this).focus();
				return;
			}
		});
	});
	
	$('body').on('click','.inputCard',function(){
		$(this).find('input').focus();
		$('body').on('blur','.inputCard input',function(){//验证身份证
			var card = $(this).val();
			var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
			if(!card){
				layer.msg('身份证号码不能为空！');
				return;
			}else if(!reg.test(card)){
				layer.msg('请输入有效的身份证号码！');
				$(this).focus();
				return;
			}
		});
	});
	
	$('body').on('click','.save',function(){
	
		var data=window.sessionStorage.getItem('setAddr');
		data=JSON.parse(data);
		console.log(data.type);
		var myreg =/^1[3|4|5|7|8]\d{9}$/,
		cardreg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
		 type = data.type,
		 isE =(type == 1) ? 0 : 1,
		 provId = $('#cityResult3').attr('data-prov'),
		 cityId = $('#cityResult3').attr('data-city'),
		 areaId = $('#cityResult3').attr('data-area'),
		 idCard = $('.inputCard input').val(),
		 aName = $('.aName').val(),
		 addr = $('.dAddr').val(),
		 tel = $('.inputTel input').val(),
		 areaD = $('#cityResult3').text()+' '+$('.dAddr').val(),
		 addrId = (type == 1) ? 0 : data.mess.id,
		 is_default = $('#switch').hasClass('mui-active') ? 1 :0 ;
		 if(!aName){
		 	layer.msg('收货人不能为空');
		 	$('.aName').focus();
		 	return false;
		 }else if(!myreg.test(tel) || !tel){
		 	layer.msg('请输入正确的手机号');
		 	$('.inputTel input').focus();
		 	return false;
		 }else if(!cardreg.test(idCard) || !idCard){
		 	layer.msg('请输入正确的身份证号');
		 	$('.inputCard input').focus();
		 	return false;
		 }else if(!$('#cityResult3').attr('data-prov')){
		 	layer.msg('所在地区不能为空');
		 }else if(!$('.dAddr').val()){
		 	layer.msg('详细地址不能为空');
		 }
		 app.ajax(
		 	'/Member/Setting/add_address',
		 	{
		 		  is_edit  : isE,
			        id       : addrId,
			        name     : aName,
			        provinceid : provId,
			        cityid     : cityId,
			        areaid     : areaId,
			        area       : areaD,
			        address    : addr,
			        idcard     : idCard,
			        mobile     : tel,
			        is_default : is_default
		 	},function(res){
		 		if(res.code == 200){
		 			layer.msg('设置地址成功~');
					setTimeout(function () {
						window.history.go(-1);
					},1000);
		 		}else{
		 			layer.msg(res.msg);
		 		}
		 	}
		 	
		 )
		 
		
	});
};

mui.init();
var cityPicker3 = new mui.PopPicker({
		layer: 3
	});
	cityPicker3.setData(cityData3);
	var showCityPickerButton = document.getElementById('showCityPicker3');
	var cityResult3 = document.getElementById('cityResult3');
	showCityPickerButton.addEventListener('click', function(event) {
		cityPicker3.show(function(items) {
			console.log(JSON.stringify(items));
			cityResult3.innerText = (items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
			$('#cityResult3').attr('data-prov',(items[0] || {}).value);
			$('#cityResult3').attr('data-city',(items[1] || {}).value);
			$('#cityResult3').attr('data-area',(items[2] || {}).value);
			//返回 false 可以阻止选择框的关闭
			//return false;
		});
}, false);